package com.xywy.bloodandroid.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xywy.bloodandroid.R;
import com.xywy.bloodandroid.act.QuestOnlineAnswerDetailAct;
import com.xywy.bloodandroid.base.BasicAdapter;
import com.xywy.bloodandroid.bean.OnlineQuestionList;

public class OnLineMessageAdapter extends BasicAdapter<OnlineQuestionList> {

	private Context context;
	private List<OnlineQuestionList> list;
	private LayoutInflater inflater;

	public OnLineMessageAdapter(Context context, List<OnlineQuestionList> list) {
		super(context, list);
		this.context = context;
		this.list = list;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		viewholder holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_online_message, null);
			holder = new viewholder();
			holder.title = (TextView) convertView
					.findViewById(R.id.expert_share_text);
			// holder.doctor = (TextView) convertView.findViewById(R.id.doctor);
			holder.date = (TextView) convertView.findViewById(R.id.time_date);
			convertView.setTag(holder);
		} else {
			holder = (viewholder) convertView.getTag();
		}

		/* 展示数据 */
		holder.title.setText(list.get(position).getTitle());

		if (list.get(position).getShortmsg() == null
				|| list.get(position).getShortmsg().length() < 1)
			holder.doctor.setText("医生暂时未回复");
		else
			holder.doctor.setText(list.get(position).getShortmsg());

		holder.date.setVisibility(View.GONE);

		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context,
						QuestOnlineAnswerDetailAct.class);
				intent.putExtra("art_id", list.get(position).getArt_id());
				context.startActivity(intent);
			}
		});
		return convertView;
	}

	private class viewholder {
		TextView title;
		TextView doctor;
		TextView date;

	}
}
